from cap14.data_define import Order
import json

class FileReader:
    file_name:str

    def __init__(self,file_name:str):
        self.file_name=file_name

    def read_data(self)->list[str]:
        with open(self.file_name, "r", encoding="utf-8") as f:
            lines = f.readlines()
            return lines

class TextFileReader(FileReader):

    def read_data(self)->list[Order]:
        lines=FileReader.read_data(self)

        results=[]
        for line in lines:
            cells = line.strip().split(",")
            results.append(Order(cells[0], cells[1], int(cells[2]), cells[3]))
        return results

class JsonFileReader(FileReader):
    def read_data(self) ->list[Order]:
        lines = FileReader.read_data(self)
        results = []
        for line in lines:
            d = json.loads(line.strip())
            results.append(Order(**d))
        return results